from flask import Flask
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from settings import db, migrate, jwt, Config, api_bp
import auth.models, auth.urls
import market.models, market.urls


class FlaskApp(object):
    def __init__(self):
        self.__app = Flask(__name__)
        self.__app.config.from_object(Config)
        self.__manager = Manager(self.__app)
        self.__manager.add_command('db', MigrateCommand)

    def set_app(self):
        db.init_app(self.__app)
        jwt.init_app(self.__app)
        migrate.init_app(self.__app, db)
        return self

    def set_router(self):
        self.__app.register_blueprint(api_bp)
        return self

    def run(self):
        self.__manager.run()


def main():
    FlaskApp().set_app().set_router().run()


if __name__ == '__main__':
    main()
